package com.turbo.cloud.ums.web.webservice;

import com.turbo.cloud.core.api.R;
import com.turbo.cloud.core.api.Result;
import com.turbo.cloud.core.validated.*;
import com.turbo.cloud.ums.web.logic.ComponentLogic;
import com.turbo.cloud.ums.web.model.component.UmsComponentQO;
import com.turbo.cloud.ums.web.model.component.UmsComponentDO;
import com.turbo.cloud.ums.web.model.component.UmsComponentVO;
import jakarta.validation.constraints.NotBlank;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 菜单组件表 前端控制器
 * </p>
 *
 * @author zhangluning
 * @since 2022-10-11
 */
@RequiredArgsConstructor
@RestController
public class UmsComponentController {
    final ComponentLogic componentLogic;


    /**
     * 根据菜单ID，查询组件列表
     *
     * @return
     */
    @PostMapping(name = "根据菜单ID，查询组件列表", value = "/webservice/component/queryComponentListByMenuId")
    public Result<List<UmsComponentVO>> queryComponentListByMenuId(@RequestBody @Validated(SelectListValidated.class) UmsComponentQO umsComponentQO) {
        List<UmsComponentVO> result = componentLogic.queryComponentListByMenuId(umsComponentQO);
        return R.result(result);
    }

    /**
     * 根据菜单ID，查询组件列表，并根据权限ID标记选中
     *
     * @return
     */
    @PostMapping(name = "根据菜单ID，查询组件列表，并根据权限ID标记选中", value = "/webservice/component/queryComponentCheckedListByMenuIdOfPermissionId")
    public Result<List<UmsComponentVO>> queryComponentCheckedListByMenuIdOfPermissionId(@RequestBody @Validated(SelectMulWhereValidated.class) UmsComponentQO umsComponentQO) {
        List<UmsComponentVO> result = componentLogic.queryComponentCheckedListByMenuIdOfPermissionId(umsComponentQO);
        return R.result(result);
    }

    /**
     * 新增组件
     *
     * @param umsComponentDO 实体
     * @return
     */
    @PostMapping(name = "新增组件", value = "/webservice/component/createComponent")
    public Result<Boolean> createComponent(@RequestBody @Validated(InsertValidated.class) UmsComponentDO umsComponentDO) {
        boolean result = componentLogic.createComponent(umsComponentDO);
        return R.result(result);
    }

    /**
     * 修改组件
     *
     * @param umsComponentDO 实体
     * @return
     */
    @PostMapping(name = "修改组件", value = "/webservice/component/modifyComponent")
    public Result<Boolean> modifyComponent(@RequestBody @Validated(UpdateValidated.class) UmsComponentDO umsComponentDO) {
        boolean result = componentLogic.modifyComponent(umsComponentDO);
        return R.result(result);
    }

    /**
     * 开启、关闭组件有效状态
     *
     * @param id 组件ID
     * @return Boolean
     */
    @GetMapping(name = "开启、关闭组件有效状态", value = "/webservice/component/enabledComponentStateById")
    public Result<Boolean> enabledComponentStateById(@RequestParam @NotBlank(message = "组件ID不能为空") String id) {
        boolean result = componentLogic.enabledComponentStateById(id);
        return R.result(result);
    }

    /**
     * 删除组件
     *
     * @param id 组件ID
     * @return
     */
    @GetMapping(name = "删除组件", value = "/webservice/component/removeComponentById")
    public Result<Boolean> removeComponentById(@NotBlank(message = "组件ID不能为空") String id) {
        boolean result = componentLogic.removeComponentById(id);
        return R.result(result);
    }
}
